using UnityEngine;

public class RuntimeGUIWindow : MonoBehaviour
{
    private bool showWindow = false;
    public Rect windowRect = new Rect(20, 20, 600, 600);

    void OnGUI()
    {
        if (showWindow)
        {
            windowRect = GUI.Window(0, windowRect, WindowFunction, "UV Editor");
        }
    }

    void WindowFunction(int windowID)
    {
        // 在窗口中绘制GUI元素
        // GUI.Label(new Rect(10, 30, 180, 20), "Hello, World!");


        GUILayout.Label("Hello, World!");


        if (GUI.Button(new Rect(Screen.width / 2 - 40, 10, 20, 20), "x"))
        {
            showWindow = false;
        }
        
        

        // 使窗口能够被拖动
        GUI.DragWindow();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            showWindow = !showWindow;
        }

        if (showWindow)
        {
            windowRect.width = Screen.width / 2f;
            windowRect.height = Screen.height / 2f;
        }
    }
}